﻿package org.dm.3d.geom 
{
	import org.dm.3d.geom.Num3D;
	
	/**
	 * ...
	 * @author Scott
	 */
	public class MathExtend 
	{
		public static var pi:Number = Math.PI;
		
		public function MathExtend() 
		{
			
		}
		public function pOnRound():void 
		{
			
		}
		public static function extendTo(v:Num3D,d:Number):Num3D
		{
			var x:Number = v.x;
			var y:Number = v.y;
			var z:Number = v.z;
			var a:Number = Math.atan2(x, y);
			var b:Number = Math.atan2(z, x);
			var c:Number = Math.atan2(y, z);
			x = d * Math.cos(a);
			//y = d * Math.sin(a);
			y = d * Math.cos(c);
			z = d * Math.cos(b);
			return new Num3D(x, y, z);
		}
		public static function pInRound(i:uint,n:uint,d:Number):Num3D 
		{
			var j:Number = i % n;
			var angle1:Number = pi / n * int(i / n);
			var angle2:Number = 2*pi / n*j;
			var x:Number = d * Math.sin(angle1);
			var y:Number = d * Math.cos(angle1);
			var z:Number = x * Math.sin(angle2);
			x *= Math.cos(angle2);
			return new Num3D(x, y, z);
		}
		public static function pInRing(n1:Number,n2:Number,r1:Number,r2:Number):Num3D 
		{
			var r:Number = r1 + r2 * Math.random();
			var n:Number = 2 * n1 * Math.random() - n1;
			var n2:Number = n2 + 8 * n1 * Math.random() - 4*n1;
			var result:Num3D = new Num3D();
			result.y = r * Math.sin(n);
			result.x = r * Math.cos(n);
			result.z = result.x * Math.cos(n2);
			result.x *= Math.sin(n2);
			return result;
		}
	}
	
}